//package cn.java83cloud.springcloudclient.service;
//
//import cn.java83cloud.springcloudclient.entity.Advtise;
//import cn.java83cloud.springcloudclient.entity.Page;
//import cn.java83cloud.springcloudclient.entity.Result;
//import cn.java83cloud.springcloudclient.util.StrUtil;
//import org.checkerframework.checker.units.qual.A;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.client.discovery.DiscoveryClient;
//import org.springframework.stereotype.Service;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.Date;
//import java.util.List;
//
///**
// * @author oldliu
// * @since 1.0
// */
//@Service
//public class AdvServiceImpl implements AdvService {
//    @Autowired
//    private RestTemplate template;
////    @Autowired
////    private DiscoveryClient discoveryClient;
//    @Override
//    public Result add(Advtise adv) {
//        // template.postForEntity()
//        return null;
//    }
//
//    //第一版：掉渣
////    @Override
//////    public Page<Advtise> search(int page, int pageSize, String title, Date start, Date end) {
//////        String url="http://localhost:9998/adv/list?page="+page+"&pageSize="+pageSize+"&title="+ StrUtil.trim(title);
//////        url+="&start="+StrUtil.toStr(start)+"&end="+StrUtil.toStr(end);
//////        return template.getForObject(url,Page.class);
//////    }
//    //第二版：实现了随机选择服务
////@Override
////public Page<Advtise> search(int page, int pageSize, String title, Date start, Date end) {
////    List<ServiceInstance> instances = discoveryClient.getInstances("springcloud-serve");
////    ServiceInstance service=instances.get((int)(instances.size()*Math.random()));
////    String url="http://"+service.getHost()+":"+service.getPort();
////    url+="/adv/list?page="+page+"&pageSize="+pageSize+"&title="+ StrUtil.trim(title);
////    url+="&start="+StrUtil.toStr(start)+"&end="+StrUtil.toStr(end);
////    return template.getForObject(url,Page.class);
////}
//    //第三版：采用ribbon负载均衡
//    @Override
//    public Page<Advtise> search(int page, int pageSize, String title, Date start, Date end) {
//
//        String url="http://springcloud-serve";
//        url+="/adv/list?page="+page+"&pageSize="+pageSize+"&title="+ StrUtil.trim(title);
//        url+="&start="+StrUtil.toStr(start)+"&end="+StrUtil.toStr(end);
//        return template.getForObject(url,Page.class);
//    }
//    //第四版：废除AdvServimpl
//}
